/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hcmus.fit.master.sevensea.control;

import hcmus.fit.master.sevensea.core.Constant;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

/**
 *
 * @author hvp
 */
public class Life {
        public static List<Bitmap> Resources;
        public int LIFE;
        public static Bitmap Icon;
        public Life(int life)
        {
            LIFE = life;
        }

        public void Show(Canvas g, int x, int y)
        {

            List<Integer> list = new ArrayList<Integer>();
            int life = LIFE;
            while (life > 0)
            {
                list.add(new Integer(life % 10));
                life /= 10;
            }
            if (list.size() <= 0)
                list.add(new Integer(0));

            x -= (list.size() * 23/2);

            g.drawBitmap(Icon,x - 20, y-2, new Paint());
            //g.drawBitmap(Icon, new Rectangle(x - 25, y, Icon.Width * 2 / 3, Icon.Height * 2/ 3), 0, 0, Icon.Width, Icon.Height, GraphicsUnit.Pixel, imgatt);

            for (int i = 0; i < list.size(); i++)
            {
                int num = ((Integer)list.get(list.size()-i-1)).intValue();
                Bitmap tmp = (Bitmap) Resources.get(num);
                int w = tmp.getWidth();
                g.drawBitmap(tmp, x + i*w, y, new Paint());
            }


        }

        public static List<Bitmap> GetResource(Bitmap resource, int maxX, int maxY, int numerator, int denominator)
        {
            List<Bitmap> rs = new ArrayList<Bitmap>();
            int w = resource.getWidth() / maxX;
            int h = resource.getHeight() / maxY;

            for (int i = 0; i < maxY; i++)
            {
                for (int j = 0; j < maxX; j++)
                {
                    Bitmap tmp = Bitmap.createBitmap(w, h, Constant.BITMAP_CONFIG);
                    Canvas g = new Canvas(tmp);
                    g.drawBitmap(resource, 0, 0, new Paint());
                    rs.add(tmp);
                }
            }
            return rs;
        }
}
